subroutine FaceVars2Chars(iFace,iCharFace,a,ACoef,EigenVal3,Sound,oppSide,Chars)
use DataFaces,only: FaceVarsOld
use DataPerfectGas, only: PressureAllVars
implicit none
    integer,intent(in) :: iFace, iCharFace, oppSide
    real(8),intent(in) :: ACoef
    real(8),intent(in) :: a(3,3) ! transformation {x,y,z} -> {normal,tan1,tan2}
    real(8),intent(out) :: EigenVal3,Sound,Chars(5)

    real(8) :: Rho,U(3),Pres

    Rho = FaceVarsOld(1,oppSide,iFace)
    U(1:3) = FaceVarsOld(2:4,oppSide,iFace)
    Pres = FaceVarsOld(5,oppSide,iFace) ! PressureAllVars(FaceVarsOld(1:5,oppSide,iFace))

    call Vars2Chars(U,Pres,Rho,iCharFace,a,ACoef,EigenVal3,Sound,Chars)

end subroutine FaceVars2Chars

subroutine CellVars2Chars(iCell,iFace,a,ACoef,EigenVal3,Sound,Chars)
use Data_Cfoam, only: U,P,Rho, Unew,Pnew,Rhonew
implicit none
    integer,intent(in) :: iCell,iFace
    real(8),intent(in) :: ACoef
    real(8),intent(in) :: a(3,3) ! transformation {x,y,z} -> {normal,tan1,tan2}
    real(8),intent(out) :: EigenVal3,Sound, Chars(5)

    call Vars2Chars(Unew(1:3,iCell),Pnew(iCell),Rhonew(iCell),iFace,a,ACoef,EigenVal3,Sound,Chars)

end subroutine CellVars2Chars

subroutine SubStepCellVars2Chars(iCell,iFace,a,ACoef,EigenVal3,Sound,Chars)
use DataCells, only: SubStepCellVars
use DataPerfectGas, only: PressureAllVars
implicit none
    integer,intent(in) :: iCell,iFace ! iFace - rudiment
    real(8),intent(in) :: ACoef
    real(8),intent(in) :: a(3,3) ! transformation {x,y,z} -> {normal,tan1,tan2}
    real(8),intent(out) :: EigenVal3,Sound,Chars(5)

    real(8) :: U(3),Pres,Rho

    U(1:3) = SubStepCellVars(2:4,iCell)
    Pres = PressureAllVars(SubStepCellVars(1:5,iCell))
    Rho = SubStepCellVars(1,iCell)

    call Vars2Chars(U,Pres,Rho,iFace,a,ACoef,EigenVal3,Sound,Chars)
    
    ! SubStepCellVars(1:5,iCell), 1:5 = Rho, Velocities, Energy

end subroutine SubStepCellVars2Chars

subroutine Vars2Chars(U,Pres,Rho,iFace,a,ACoef,Chars3,Sound,Chars)
use DataPerfectGas, only: GammX, GammY, GammPower, EntropyPRho, SoundVelocityPRho
use Data_Mesh,only: meshSf
implicit none
    real(8),intent(in) :: U(3),Pres,Rho, ACoef
    integer,intent(in) :: iFace
    real(8),intent(in) :: a(3,3) ! transformation {x,y,z} -> {normal,tan1,tan2}
    real(8),intent(out) :: Chars3,Sound,Chars(5)

    real(8) :: Ut(3) ! transformed U(1:3) into {normal,tan1,tan2}
    real(8) :: Q,R,S,W1,W2
    real(8) :: Apmu
    
    call transform(U,Ut(1:3),a)

    S = EntropyPRho(Pres,Rho)
!    ACoef = GammY * S**GammPower 
    Apmu = ACoef * Pres**GammX
    Q = Ut(1) - Apmu
    R = Ut(1) + Apmu
    W1 = Ut(2)
    W2 = Ut(3)
    
    Chars(1) = Q
    Chars(2) = R
    Chars(3) = S
    Chars(4) = W1
    Chars(5) = W2
    
    Chars3 = Ut(1)
    Sound = SoundVelocityPRho(Pres,Rho)

end subroutine Vars2Chars

subroutine PresRhoU2Chars(U,Pres,Rho,Acoef,Chars)
use DataPerfectGas, only: EntropyPRho, ACoefPRho, GammX
use Data_Mesh,only: meshSf
implicit none
    real(8),intent(in) :: U(3),Pres,Rho
    real(8),intent(out) :: Acoef,Chars(5)

    real(8) :: Q,R,S,W1,W2
    real(8) :: Apmu

    ACoef = ACoefPRho(Pres,Rho) ! GammY * (Pres * Rho**(-Gamma))**GammPower
    Apmu = ACoef * Pres**GammX
    Q = U(1) - Apmu
    R = U(1) + Apmu
    S = EntropyPRho(Pres,Rho)
    W1 = U(2)
    W2 = U(3)
    
    Chars(1) = Q
    Chars(2) = R
    Chars(3) = S
    Chars(4) = W1
    Chars(5) = W2
    
!    Chars3 = Ut(1)
!    Sound = SoundVelocityPRho(Pres,Rho)

end subroutine PresRhoU2Chars
